<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="设备名称" prop="equipmentName">
        <el-input
          v-model="queryParams.equipmentName"
          placeholder="请输入设备名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安装单位" prop="installationUnit">
        <el-input
          v-model="queryParams.installationUnit"
          placeholder="请输入安装单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div>
        <el-row :gutter="20">
          <el-col
            :span="24"
            :class="{ line: index + 1}"
            v-for="(item, index) in nmEquipmentList"
            :key="index"
          >
            <div style="text-align:center">
              <p>设备二维码管理</p>
              <ImagePreview :src="item.qrImage" :width="200" :height="200" />
              <p>{{ item.equipmentNo }}</p>
            </div>
          </el-col>
        </el-row>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes="pageSizes"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listNmEquipment, getNmEquipment, delNmEquipment, addNmEquipment, updateNmEquipment, exportNmEquipment } from "@/api/jetLinks/nmEquipment";
import ImageUpload from '@/components/ImageUpload';
import ImagePreview from "@/components/ImagePreview";
export default {
  name: "NmEquipment",
  components: {
    ImageUpload,ImagePreview
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备信息管理表格数据
      nmEquipmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 自定义分页
      pageSizes: [12, 24, 48, 96],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        equipmentWorkshop: null,
        equipmentImg: null,
        equipmentRenark: null,
        equipmentNo: null,
        productionDate: null,
        num: null,
        equipmentName: null,
        installationUnit: null,
        productionNo: null,
        model: null,
        overallDimension: null,
        totalWeight: null,
        liftingWeightMax: null,
        manufacturer: null,
        productionTime: null,
        medium: null,
        designFlow: null,
        speed: null,
        inletTemperature: null,
        normalFlow: null,
        shaftPower: null,
        viscosity: null,
        inletPressure: null,
        cavitationAllowance: null,
        lift: null,
        outletPressure: null,
        suctionTemperature: null,
        driving: null,
        drivingSpeed: null,
        explosionProofGrade: null,
        drivingMachine: null,
        drivingProductionDate: null,
        drivingManufacturer: null,
        equipmentOperationParameters: null,
        intermediateMaintenanceCycle: null,
        overhaulCycle: null,
        qrImage: 1,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备信息管理列表 */
    getList() {
      this.loading = true;
      listNmEquipment(this.queryParams).then(response => {
        this.nmEquipmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equipmentWorkshop: null,
        equipmentImg: null,
        equipmentRenark: null,
        equipmentNo: null,
        productionDate: null,
        num: null,
        equipmentName: null,
        installationUnit: null,
        productionNo: null,
        model: null,
        overallDimension: null,
        totalWeight: null,
        liftingWeightMax: null,
        manufacturer: null,
        productionTime: null,
        medium: null,
        designFlow: null,
        speed: null,
        inletTemperature: null,
        normalFlow: null,
        shaftPower: null,
        viscosity: null,
        inletPressure: null,
        cavitationAllowance: null,
        lift: null,
        outletPressure: null,
        suctionTemperature: null,
        driving: null,
        drivingSpeed: null,
        explosionProofGrade: null,
        drivingMachine: null,
        drivingProductionDate: null,
        drivingManufacturer: null,
        equipmentOperationParameters: null,
        intermediateMaintenanceCycle: null,
        overhaulCycle: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNmEquipment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNmEquipment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNmEquipment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除设备信息管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNmEquipment(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有设备信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportNmEquipment(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
  .line {
  //  border-right: 1px solid rgb(71, 8, 8);
    float:left;
    width:260px;
    height:330px;
    margin:8px;
    padding:8px;
    border:dashed 1px #ccc;
    display:flex;
    justify-content:center;/*主轴上居中*/
    align-items:center;/*侧轴上居中*/
  }

</style>
